import StatusNav from '@/components/school/statusNav';
import {mapGetters} from "vuex";
import * as GroupApi from '@/api/school/groupinfo.js';
import * as OrderApi from '@/api/school/order.js';
import diyJson from '@/config/diy.js';

export const mixins =
    {
      computed: mapGetters(['uid', 'userInfo', 'shareInfo', 'schoolId']),
      components: {
        StatusNav,
      },
      data() {
        return {
          swiperCurrent: 0,

          btnDisabled: false,

          themConfig: diyJson.commonStyle,

          pageBody: {
            paddingBottom: 65,
          },
          groupInfo: undefined,
          num: 1,
          urlParams: undefined,
          order: {
            list: [],
            ext: {
              count: 0,
              amount: 0.00
            }
          }
        };
      },

      onLoad: function (options) {
        let p = options.params;
        if (p) {
          let params = JSON.parse(decodeURIComponent(p));
          this.urlParams = params;
          // console.log("params", params)
          this.detailData(params.activityId);
        }
      },

      created() {
      },

      onShow() {
        this.getGroupOrder();
      },
      mounted() {
      },

      methods: {

        detailData(id) {
          GroupApi.groupDetail(id).then(res => {
            this.groupInfo = res.data
          });
        },

        getGroupOrder() {
          OrderApi.activityOrders(
              {activityBaseId: this.urlParams.activityBaseId, size: 100}).then(
              res => {
                this.order.list = res.data.records
                this.order.ext = res.data.ext
              })
        },
        acctOrder(item) {
          OrderApi.takeOrder({orderId: item.id}).then(res => {
            this.$refs.notify.show({
              message: '已接单',
              duration: 500,
              safeAreaInsetTop: true
            });
            this.getGroupOrder()
          })
        },
        cancelOrder(item) {
          OrderApi.cancelOrder({orderId: item.id,cancelType:6}).then(res => {
            this.$refs.notify.show({
              message: '已取消退款',
              duration: 500,
              safeAreaInsetTop: true
            });
            this.getGroupOrder();
          })
        },
        finishOrder(item) {
          OrderApi.doneOrder({orderId: item.id}).then(res => {
            this.$refs.notify.show({
              message: '已完成',
              duration: 500,
              safeAreaInsetTop: true
            });
            this.getGroupOrder();
          })
        },
      },
      onReachBottom() {

      }
    }
